package com.ins.controller;

import com.ins.common.utils.Result;
import com.ins.model.entity.AppPromotion;
import com.ins.model.query.Query;
import com.ins.model.vo.AppPromotionVO;
import com.ins.service.AppPromotionService;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * 推广记录
 *
 * @author ins
 * @since 2024-05-14
 */
@RestController
@RequestMapping("/promotion")
public class AppPromotionController {

    @Resource
    private AppPromotionService appPromotionService;

    /**
     * 添加 推广记录
     *
     * @param appPromotion 推广记录
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("/save")
    public Result<Boolean> save(@RequestBody AppPromotion appPromotion) {
        return Result.ok(appPromotionService.save(appPromotion));
    }


    /**
     * 根据主键删除推广记录
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("/remove/{id}")
    public Result<Boolean> remove(@PathVariable Serializable id) {
        return Result.ok(appPromotionService.removeById(id));
    }


    /**
     * 根据主键更新推广记录
     *
     * @param appPromotion 推广记录
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PutMapping("/update")
    public Result<Boolean> update(@RequestBody AppPromotion appPromotion) {
        return Result.ok(appPromotionService.updateById(appPromotion));
    }


    /**
     * 查询所有推广记录
     *
     * @return 所有数据
     */
    @GetMapping("/list")
    public Result<List<AppPromotion>> list() {
        return Result.ok(appPromotionService.list());
    }


    /**
     * 根据推广记录主键获取详细信息。
     *
     * @param id appPromotion主键
     * @return 推广记录详情
     */
    @GetMapping("/getInfo/{id}")
    public Result<AppPromotionVO> getInfo(@PathVariable Long id) {
        return Result.ok(appPromotionService.getInfo(id));
    }


    /**
     * 分页查询推广记录
     *
     * @param query 分页对象
     * @return 分页对象
     */
    @GetMapping("/page")
    public Result<Page<AppPromotionVO>> pages(Query query) {
        return Result.ok(appPromotionService.pages(query));
    }
}